<?php
namespace app\middleware;

use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;

class AdminCheck implements MiddlewareInterface
{
    public function process(Request $request, callable $next) : Response
    {
        //无需验证码控制器数组
        $arr = [
            'admin' => [
                'app\admin\controller\Login' => [
                        'verify',
                        'index'
                    ]
                ],
        ];

        //验证登录
        if ((new \app\admin\model\AdminAdmin)->isLogin()==false) {
            if(empty($arr[$request->app][$request->controller])){
                return redirect(APP_ADMIN.'/login/index');
            }else if (!in_array($request->action,$arr[$request->app][$request->controller])) {
                return redirect(APP_ADMIN.'/login/index');
            }
        }
        return $next($request);
    }
}

